package com.itheima.flowcontrol.demo;

import java.util.Random;

/**
 * 生成随机位数的验证码
 */
public class Test3 {
    public static void main(String[] args) {
        System.out.println(getCode(4));
        System.out.println(getCode(5));

    }
    public static String getCode(int n){
        String code = "";
        Random random = new Random();
        for (int i = 0; i < n; i++) {
            int type = random.nextInt(3);
            // 0 : 数字 0-9
            // 1 : 大写字母 A-Z
            // 2 : 小写字母 a-z
            switch (type){
                case 0:
                   int num = random.nextInt(10);
                   code += num;
                    break;
                case 1:
                    int num1 = random.nextInt(26) + 65;
                    code += (char)num1;
                    break;
                case 2:
                    int num2 = random.nextInt(26) + 97;
                    code += (char)num2;
                    break;
            }
        }
        return code;
    }
}
